class Food{
    constructor(el){
        this.el = el
        this.len = 20
        this.foodX = 0
        this.foodY = 0
        this.foodObj = null
    }

    foodCreate(){
        let divObj = document.createElement('div')
        divObj.style.position = 'absolute'
        divObj.style.width = this.len + 'px'
        divObj.style.height = this.len + 'px'
        divObj.style.background = 'url(./img/food.gif)'
        divObj.style.backgroundSize =  `${this.len}px ${this.len}px`
        this.foodObj = divObj
        this.el.appendChild(divObj)
    }
    // 随机数方法//普通方法
    random(min,max){
        return Math.floor(Math.random() * (max - min + 1) + min )
    }
    foodMove(){
        let maxW = this.el.clientWidth / this.len
        let maxH = this.el.clientHeight / this.len
        this.foodX = this.random(0,maxW-1) * this.len
        this.foodY = this.random(0,maxH-1) * this.len
        console.log( this.foodX, this.foodY);
        this.foodObj.style.left = this.foodX + 'px'
        this.foodObj.style.top = this.foodY + 'px'
        

    }

}